#!/bin/bash

. $OPENARS_HOME/common/debug.h
. $OPENARS_HOME/common/functions.h

if [ "$ORACLE_ENABLE" = "Y" ]; then
    if [ -z "$CONNECT_ARS" ]; then
        ERR "not defined CONNECT_ARS environment for Oracle connect. exit."
        exit 1;
    fi
    INF "this script test HOST/IP in table HOSTS"
    host_ip_lst=`$ORACLE_HOME/bin/sqlplus -s /NOLOG  <<END
set PAGESIZE 0 ECHO OFF FEEDBACK OFF HEADING OFF TERMOUT OFF VERIFY OFF
connect $CONNECT_ARS
select s.host||':'||s.ip from hosts s where s.os='Unix' and s.control='YES';
exit;
END`
INF "count hosts: `echo $host_ip_lst | wc -w`"
for i in $host_ip_lst
do
    host=`echo $i | awk -F: '{print $1}'`	
    ip=`echo $i | awk -F: '{print $2}'`
    /usr/sbin/nslookup $host 2>/dev/null | grep " $ip$" >/dev/null
    [ $? != "0" ] && ERR "table HOSTS have NOT correct information $host:$ip"
done

else
    INF "this script test HOST/IP in file hosts.conf"
    format_host | grep os=\"Unix\" | grep control=\"YES\" > $TEMPDIR/hosts.conf.tmp
while read line
do
    host=`echo $line | get_xmlparam host`
    ip=`echo $line | get_xmlparam ip`
    echo $host:$ip
    /usr/sbin/nslookup $host 2>/dev/null | grep " $ip$" >/dev/null
    [ $? != "0" ] && ERR "file hosts.conf have NOT correct information $host:$ip"
done < $TEMPDIR/hosts.conf.tmp
fi

exit 0
